/*
 * 
 * Version 1.00
 * 
 * Created on 2007-6-4
 * Encoding GB2312
 */
package net.comm.user.service.impl;

import java.sql.Connection;
import java.util.List;

import net.comm.common.GlbFinal;
import net.comm.common.ReturnMessage;
import net.comm.common.common;
import net.comm.file.service.impl.FilesServiceImpl;
import net.comm.file.web.form.FilesForm;

import net.comm.shequ.db.DbWyYanzhService;
import net.comm.shequ.db.WyYanzhServiceSqlMysql;
import net.comm.user.bean.BaseUsertemp;
import net.comm.user.db.DbUsertempService;
import net.comm.user.db.UsertempServiceSqlMysql;
import net.comm.user.web.form.UsertempForm;
import net.comm.util.DbcpPool;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;
import org.sakaiproject.db.impl.BasicSqlService;


/**
 *
 * @author hcgong(hcgong@sina.com)
 * @version 1.0
 * @date 2007-6-4
 */
public class UsertempServiceImpl {

	static Logger logger = Logger.getLogger(UsertempServiceImpl.class.getName());

	/**
	 * 
	 * @see net.IUserbasicService.module.other.IUserService
	 * 		#list(net.swift.module.other.ExaQueryBean, net.swift.common.ReturnMessage)
	 */
	public List list(UsertempForm theForm,  ReturnMessage msg) 
	{
		List list = null;
		
		return list;
	}

	/**
	 * @see net.IUserbasicService.module.other.IUserService
	 * 		#get(net.swift.db.tab_paramnostro, net.swift.common.ReturnMessage)
	 */
	public void get(UsertempForm theForm, ReturnMessage msg) 
	{

		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			
			get(cn, theForm, msg);
			if(msg.getErrCode() != 0){
				return;
			}

			DbcpPool.closeTran(cn);			
			DbcpPool.returnConnection(cn);
		} catch(Exception ex) 
		{
			logger.error("System error , param get about invite" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return ;
	}
	/**
	 * @see net.IUserbasicService.module.other.IUserService
	 * 		#get(net.swift.db.tab_paramnostro, net.swift.common.ReturnMessage)
	 */
	public void get(Connection cn, UsertempForm theForm, ReturnMessage msg) 
	{

		try
		{
			
			UsertempServiceSqlMysql servSql = new UsertempServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();
			
			//取得FORM中传入的查询参数
			Object[] fields1 = new Object[1];
			fields1[0] = theForm.getUserID();
						
			String sql = servSql.getbykeySql();
						
			List list = bSqlServ.dbRead(cn, sql, fields1, new DbUsertempService());
			if(list.size() == 0){
				common.setAppFailMsg(msg , " 取记录失败！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;				
			}
			BaseUsertemp base = (BaseUsertemp)list.get(0);
			BeanUtils.copyProperties(theForm, base);

		} catch(Exception ex) 
		{
			logger.error("System error , param get about invite" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
		}
		
		return ;
	}
	/**
	 * 添加会员操作日志到表中
	 * @see net.IUserbasicService.module.other.IUserService#add(net.swift.common.ReturnMessage)
	 */
	public void add(UsertempForm theForm, ReturnMessage msg) 
	{
		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			
			DbcpPool.beginTran(cn);

			add( cn,  theForm, msg);
			
			DbcpPool.commitTran(cn);
			DbcpPool.closeTran(cn);			
			DbcpPool.returnConnection(cn);
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about invite" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}				
			
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return ;
	}
	
	/**
	 * 添加会员操作日志到表中
	 * @see net.IUserbasicService.module.other.IUserService#add(net.swift.common.ReturnMessage)
	 */
	public void add(Connection cn, UsertempForm theForm, ReturnMessage msg) 
	{
		try
		{

			UsertempServiceSqlMysql servSql = new UsertempServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();
			
			//上传个人照片
			if(theForm.getPicIDPath() != null&&!theForm.getPicIDPath().getFileName().equals("")){
				
				FilesForm fileForm = new FilesForm();
				fileForm.setFormFile(theForm.getPicIDPath());
				fileForm.setF_info(theForm.getName());
				fileForm.setF_Zip(GlbFinal.ZIP_135_110);
				
				FilesServiceImpl fileservice = new FilesServiceImpl();
				
				fileservice.add(cn, fileForm, msg);
				if(msg.getErrCode() != 0){
					return ;
				}
				theForm.setPicID(fileForm.getF_ID());
			}				
			
			//上传房产照片
			if(theForm.getFcPicIDPath() != null&&!theForm.getFcPicIDPath().getFileName().equals("")){
				
				FilesForm fileForm = new FilesForm();
				fileForm.setFormFile(theForm.getFcPicIDPath());
				fileForm.setF_info(theForm.getName());
				fileForm.setF_Zip(GlbFinal.ZIP_200_200);
				
				FilesServiceImpl fileservice = new FilesServiceImpl();
				
				fileservice.add(cn, fileForm, msg);
				if(msg.getErrCode() != 0){
					return;
				}
				theForm.setFcPicID(fileForm.getF_ID());
			}				
			
			//取得FORM中传入的查询参数
			Object[] fields = new Object[67];
			
			fields[0] = theForm.getUserID();			//	会员ID
			fields[1] = theForm.getNick();			//	用户名
			fields[2] = theForm.getName();			//	真实姓名
			fields[3] = theForm.getIntroduction();	//	自我评价/个性签名
			fields[4] = theForm.getPicID();			//	个人照片ID
			fields[5] = theForm.getSex();			//	性别
			fields[6] = theForm.getWork();			//	目前职业
			fields[7] = theForm.getWorkSet();		//	职业隐私保护
			fields[8] = theForm.getSkill();			//	特长
			fields[9] = theForm.getSkillSet();		//	特长隐私保护
			fields[10] = theForm.getBirthday();		//	出生日期
			fields[11] = theForm.getBirthdaySet();	//	出生日期隐私保护
			fields[12] = theForm.getStar();			//	星座
			fields[13] = theForm.getChzodiac();		//	生肖
			fields[14] = theForm.getNationality();		//	国籍
			fields[15] = theForm.getPepole();			//	民族
			fields[16] = theForm.getPolity();			//	政治面貌
			fields[17] = theForm.getJoinWorkTime();	//	参加工作时间
			fields[18] = theForm.getHome_location();		//	户口省份
			fields[19] = theForm.getHome_sublocation();	//	户口城市
			fields[20] = theForm.getHome_area();			//	户口区县
			fields[21] = theForm.getHome_town();		//	户口镇（街道）
			fields[22] = theForm.getHome_Set();		//	户口所在地隐私保护
			fields[23] = theForm.getCerttype();		//	证件类型
			fields[24] = theForm.getCertno();			//	证件号码
			fields[25] = theForm.getCertSet();		//	证件隐私保护
			fields[26] = theForm.getMarriage();		//	婚姻状况
			fields[27] = theForm.getIsArmy();			//	是否服役
			fields[28] = theForm.getArmy();			//	服役
			fields[29] = theForm.getArmySet();		//	服役隐私保护
			fields[30] = theForm.getEducation();		//	学历
			fields[31] = theForm.getHighSchool();		//	毕业中学
			fields[32] = theForm.getHsFinshDate();	//	中学毕业时间
			fields[33] = theForm.getCollege();		//	毕业大学
			fields[34] = theForm.getColFinshDate();	//	大学毕业时间
			fields[35] = theForm.getSchoolSet();		//	中学隐私保护
			fields[36] = theForm.getInterest();		//	爱好关注
			fields[37] = theForm.getInterestSet();	//	爱好隐私保护
				
			fields[38] = theForm.getWork_location();	//	所在省份
			fields[39] = theForm.getWork_sublocation();	//	所在城市
			fields[40] = theForm.getWork_area();			//	所在区县
			fields[41] = theForm.getVillageID();			//	小区
			fields[42] = theForm.getBuilding();			//	栋
			fields[43] = theForm.getHouseNo();			//	号
			fields[44] = theForm.getFangchanNo();			//	房产证号码
			fields[45] = theForm.getFcNoSet();			//	房产证号码隐私保护
			fields[46] = theForm.getFcPicID();			//	房产证照片ID
			fields[47] = theForm.getFcPicIDSts();			//	房产证照片状态
			fields[48] = theForm.getInTime();			//	入住时间
			fields[49] = theForm.getInTimeSet();		//	入住时间隐私保护
			fields[50] = theForm.getFamSts();			//	家庭状况
			fields[51] = theForm.getFamStsSet();		//	家庭状况隐私保护
			fields[52] = theForm.getLiveSts();		//	居住状况
			fields[53] = theForm.getLiveStsSet();		//	居住状况隐私保护
				
			fields[54] = theForm.getOffwebsite();	//官方网址
			fields[55] = theForm.getPerwebsite();	//个人网址
			fields[56] = theForm.getBlog();		//个人博客
			fields[57] = theForm.getMobile();		//手机
			fields[58] = theForm.getTel();		//商务电话
			fields[59] = theForm.getFamtel();		//家庭电话
			fields[60] = theForm.getFax();		//传真号码
			fields[61] = theForm.getQQ();			//
			fields[62] = theForm.getMsn();		//
			fields[63] = theForm.getEmail();		//Email
			fields[64] = theForm.getAddr();		//通讯地址
			fields[65] = theForm.getPostcode();	//邮编

			fields[66] = theForm.getMtime();			//	最后修改日期
			
			fields[67] = theForm.getSchoolSet2();		//	大学隐私保护
						
			String sql = servSql.getInsertSql();
						
			boolean  res = bSqlServ.dbWrite(cn, sql, fields);
			if(!res){
				common.setAppFailMsg(msg , " 插入记录失败！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;
			}
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about invite" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		}
		
		return ;
	}	
	/**
	 * 删除一条指定记录
	 * @see net.IUserbasicService.module.other.IUserService#update(net.swift.common.ReturnMessage)
	 */
	public void delete(UsertempForm theForm, ReturnMessage msg) 
	{
		
		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			
			DbcpPool.beginTran(cn);
			
			delete( cn, theForm, msg);
			if(msg.getErrCode() != 0){
				return;
			}

			DbcpPool.commitTran(cn);
			DbcpPool.closeTran(cn);
			DbcpPool.returnConnection(cn);
			return;
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about info" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return ;
	}
	/**
	 * 删除一条指定记录
	 * @see net.IUserbasicService.module.other.IUserService#update(net.swift.common.ReturnMessage)
	 */
	public void delete(Connection cn, UsertempForm theForm, ReturnMessage msg) 
	{
		
		try
		{
			
			UsertempServiceSqlMysql servSql = new UsertempServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();

			//取得FORM中传入的查询参数
			Object[] fields2 = new Object[1];
			
			fields2[0] = theForm.getUserID();
			
			String sql = servSql.getDeleteSql();
			
			boolean  res = bSqlServ.dbWrite(cn, sql, fields2);
			if(!res){
				common.setAppFailMsg(msg , " 删除项目记录失败，请检查！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;
			}

			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about info" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
		}
		
		return ;
	}	
	/**
	 * 更新一条指定记录
	 * @see net.IUserbasicService.module.other.IUserService#update(net.swift.common.ReturnMessage)
	 */
	public void update(UsertempForm theForm, ReturnMessage msg) 
	{
				
		return ;
	}

}
